package com.cellulam.framework.test.utils.test;

import org.junit.Assert;

import java.util.Collection;

public class AssertsItem<T> {
    private T value;

    public AssertsItem(T value) {
        this.value = value;
    }

    public void isEqualTo(T except) {
        Assert.assertEquals(except, this.value);
    }

    public void in(Collection<T> collection) {
        for (T except : collection) {
            if (this.value.equals(except)) {
                return;
            }
        }

        throw new AssertionError("[" + value + "] not in collection: " + collection.toString());
    }

    public void contains(T except) {
        if (!(this.value instanceof Collection)) {
            throw new AssertionError("[" + value + "] is not a collection");
        }

        for (T item : (Collection<T>) value) {
            if(item.equals(except)) {
                return;
            }
        }
        throw new AssertionError("[" + value + "] not contains: " + except);
    }
}
